package email

import (
	"mime"

	"net/http"

	"path/filepath"
)

func (e *Email) AttachFileURL(fileURL string) (a *Attachment, err error) {
	resp, err := http.Get(fileURL)
	if err != nil {
		return
	}
	defer resp.Body.Close()

	ct := mime.TypeByExtension(filepath.Ext(fileURL))
	basename := filepath.Base(fileURL)
	return e.Attach(resp.Body, basename, ct)
}
